package com.omaitec.log4j.mq.expand;

import javax.jms.Connection;
import javax.jms.MessageConsumer;
import javax.jms.Session;

import org.apache.activemq.ActiveMQConnectionFactory;

public class Log4jConsumer extends Thread {

    Session sess;

    public Log4jConsumer() throws Exception {
	ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
		"tcp://localhost:61616");
	Connection conn = factory.createConnection();
	sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
	conn.start();
	MessageConsumer consumer = sess.createConsumer(sess
		.createQueue("logQueue"));
	consumer.setMessageListener(new LogMessageListener());
    }

    @Override
    public void run() {
	while (true) {
	    try {
		Thread.sleep(1000);
	    } catch (InterruptedException e) {
		e.printStackTrace();
	    }

	}
    }

}
